/**
 * 
 */
package dk.aiszone.lang.autosource.generatorobjects.helpers;

import dk.aiszone.lang.autosource.generatorobjects.interfaces.SimpleBlockObject;

/**
 * Simple implementation of a <code>SimpleBlockObject</code> containin a <code>String</code>.
 * 
 * @author Ais
 */
public class StringBlock implements SimpleBlockObject {

    /* pp */final StringBuilder part;

    /**
     * Constructor for the <code>StringBlock</code> object.
     * 
     * @param string
     *            The <code>String</code> to contain.
     */
    public StringBlock(String string) {
        part = new StringBuilder(string);
    }

    /* pp */StringBlock(StringBuilder part) {
        this.part = part;
    }

    @Override
    public Object clone() {
        return new StringBlock(new StringBuilder(part));
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof StringBlock) {
            StringBlock other = (StringBlock)obj;
            return part.toString().equals(other.part.toString());
        }
        return false;
    }

    @Override
    public SimpleBlockObject getChild(int index) {
        throw new UnsupportedOperationException("StringBlock doesn't have any children.");
    }

    @Override
    public int getChildCount() {
        return 0;
    }

    @Override
    public int hashCode() {
        return part.toString().hashCode();
    }

    @Override
    public String toJava() {
        return part.toString();
    }

    @Override
    public String toString() {
        return part.toString();
    }
}